from models import EnterpriseAccount
from utils import auth
from utils import utils


class EnterpriseAccountService:

    def __init__(self):
        pass

    @classmethod
    async def insert(cls, user: str, enterprise_id: str, tenant_id: str):
        uid = utils.get_uid()
        data_dict = {
            "create_user": user,
            "update_user": user,
            "tenant_id": tenant_id,
            "uid": uid,
            "account_id": user,
            "enterprise_id": enterprise_id,
        }

        await EnterpriseAccount(**data_dict).save()

    @classmethod
    async def get_tenant(cls, user_id):
        ea = await EnterpriseAccount.get_or_none(account_id=user_id)
        if ea is None:
            return None
        return ea.tenant_id
